//
//  DownloadImagesViewModel.swift
//  FileManager-NSCache-HttpDownload
//
//  Created by DaleGuo on 2023/9/19.
//

import Foundation
import Combine

//viewModel中图片数据（公共）来自service，且service为Publisher，
//viewModel订阅Service
class DownloadImagesViewModel: ObservableObject {
    @Published var dataArray: [PhotoModel] = []
    let photoModelDataService = PhotoModelDataService.instance
    
    var cancellables = Set<AnyCancellable>()
    
    init() {
        addSubscriber()
    }
    
    
    func addSubscriber() {
        photoModelDataService.$photoModels
            .sink { [weak self] returnedModelData in
                self?.dataArray = returnedModelData
            }
            .store(in: &cancellables)
    }
}
